all files / timePicker/ timeDisplay.vue

10% Statements 2/20
0% Branches 0/10
0% Functions 0/8
5.88% Lines 1/17
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83                                                                                                                                                                     
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
 
export default {
  props: {
    affix: {
      type: String,
      default: '',
      validator (val) {
        return ['', 'pm', 'am'].indexOf(val) !== -1
      }
    },
    format: {
      type: String,
      validator (val) {
        return val && ['ampm', '24hr'].indexOf(val) !== -1
      }
    },
    mode: {
      type: String,
      default: 'hour',
      validator (val) {
        return ['hour', 'minute'].indexOf(val) !== -1
      }
    },
    selectedTime: {
      type: Date,
      default () {
        return new Date()
      },
      required: true
    }
  },
  methods: {
    handleSelectAffix (affix) {
      this.$emit('selectAffix', affix)
    },
    handleSelectHour () {
      this.$emit('selectHour')
    },
    handleSelectMin () {
      this.$emit('selectMin')
    }
  },
  computed: {
    sanitizeTime () {
      let hour = this.selectedTime.getHours()
      let min = this.selectedTime.getMinutes().toString()
 
      if (this.format === 'ampm') {
        hour %= 12
        hour = hour || 12
      }
 
      hour = hour.toString()
      if (hour.length < 2) hour = `0${hour}`
      if (min.length < 2) min = `0${min}`
 
      return [hour, min]
    }
  }
}